<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
 pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@page import="eBrain.beans.Item"%>
<%@page import="eBrain.beans.Bid"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.Iterator"%>
<jsp:useBean id="dataManager" scope="application"
  class="eBrain.model.DataManager"/>
  
<%String base = (String)application.getAttribute("base"); %>
   
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" href="/eBrain/css/eshop.css" type="text/css"/>
</head>
<body>
<jsp:include page="TopMenu.jsp" flush="true"/>
<jsp:include page="LeftMenu.jsp" flush="true"/>

<% 	
		Item item = (Item)session.getAttribute("itemInfo");		
		%>

 
    <form action="<%=base%>?action=updateItem" method="post">
    	<table>
        <tr>
          <td>Name:</td>
          <td>
            <input type="text" name="name"
              value="<%=item.getName().trim()%>">
          </td>
        </tr>
        <tr>
          <td>Start:</td>
          <td>
            <input type="text" name="start"
               value="<%=item.getStart().toGMTString()%>">
          </td>
        </tr>
        <tr>
          <td>Ende:</td>
          <td>
            <input type="text" name="end"
               value="<%=item.getEnd().toGMTString()%>">
          </td>
        </tr>
        <tr>
          <td>Gebot</td>
          <td>
            <input type="text" name="description"
               value="<%=item.getDescription().trim()%>">
          </td>
        </tr>
       
          <tr>
          <td colspan=2>
            <input type="submit" value="Send Data">
          </td>
        </tr>
      </table>
    
     <div>  
     	<font color="red">
      			<%	String msg = (String)session.getAttribute("msg");
      				if(msg!=null){
     					out.print(msg);
     					session.removeAttribute("msg");
      				} %>
   		 </font>
    </div>
    </form>
    
    <a class="link2" href="<%=base%>?action=bid">Bieten</a>
    
    <%
        ArrayList bids = (ArrayList)dataManager.getBidsForItem(item.getId());
        Iterator iterator = bids.iterator();
        if(!bids.isEmpty()){
          
  %>
    
    <p>Bids: <strong></strong></p>
      <table>
        <tr>
          <th>Bid Value</th>
          <th>User</th>
          <th>Timestamp</th>
          
          </tr>
          <%while (iterator.hasNext()) {
          Bid bid = (Bid)iterator.next(); %>
          <tr>
            <td><%=bid.getBidValue()%></td>
            <td><%=dataManager.getUsernameByUserId(bid.getUserId())%></td>
            <td><%=bid.getTimestamp().toString()%></td>
            
            </tr>
<%
          }
          }
          else{
  %>
  		<p>No bids for this item. <strong></strong></p>
  <%
  	} %>
        </table>
    
 
</body>
</html>